// import { createStore, applyMiddleware, combineReducers } from 'redux';
import { createStore, applyMiddleware, combineReducers } from '../yl-redux';

// import thunk from 'redux-thunk';
// import logger from 'redux-logger';
import thunk from '../yl-redux-middleware/yl-thunk';
import logger from '../yl-redux-middleware/yl-logger';
import promise from '../yl-redux-middleware/yl-promise';

/*
 * @description: 首先就是要搞清楚 Reducer的格式，Reducer是一个纯函数，主要作用是用来无副作用的修改 state，所以他的参数有两个，一个是当前的state，一个是我们要派发的动作(acton)，Reducer要做的事情就是根据 action修改 state，并最终返回操作完成后的state
 */
export const counterReducer = (state = 0, { type, payload }) => {
  switch (type) {
    case 'ADD':
      return state + payload;
    case 'MINUS':
      return state - payload;
    default:
      return state;
  }
};

// const store = createStore(counterReducer, applyMiddleware(promise, thunk, logger));
const store = createStore(combineReducers({ count: counterReducer }), applyMiddleware(promise, thunk, logger));

export default store;
